import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * hidden: true    如果设置为true则不会显示在侧边菜单               
 * alwaysShow: true   设置为true一直显示根路由                        
 * redirect: noRedirect  当设置 noRedirect 的时候该路由在面包屑导航中不可被点击         
 * name:'router-name'    设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * meta : {
    roles: ['admin','editor']    设置该路由进入的权限，支持多个权限叠加
    title: 'title'               设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'            设置该路由的图标
    breadcrumb: false             如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/example/list'    如果设置了激活菜单，则侧边菜单会默认选中
  }
 */

//固定路由，所有的人都可以访问
export const constantRoutes = [{
        path: "/login",
        component: () =>
            import ("@/views/login/index"),
        hidden: true
    },

    {
        path: "/404",
        component: () =>
            import ("@/views/404"),
        hidden: true
    },

    {
        path: "/",
        component: Layout,
        redirect: "/dashboard",
        children: [{
            path: "dashboard",
            name: "Dashboard",
            component: () =>
                import ("@/views/dashboard/index"),
            meta: { title: "首页", icon: "dashboard" }
        }]
    },
    {
        path: "/user",
        component: Layout,
        children: [{
            path: "index",
            name: "user",
            component: () =>
                import ("@/views/user/user"),
            meta: { title: "用户管理", icon: "dashboard" }
        }]
    },

    //404界面
    { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
    new Router({
        // mode: 'history', // 上线前可以设置为history，但是需要后台支持配置
        scrollBehavior: () => ({ y: 0 }),
        routes: constantRoutes
    });

const router = createRouter();

//重置路由
export function resetRouter() {
    const newRouter = createRouter();
    router.matcher = newRouter.matcher; // reset router
}

export default router;